package com.haredot.config;

import com.haredot.interceptor.IpRateInterceptor;
import com.haredot.interceptor.properties.IpRateProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.script.RedisScript;

@ConditionalOnClass(RedisScript.class)
@EnableConfigurationProperties(IpRateProperties.class)
public class IpRateAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(IpRateInterceptor.class)
    public IpRateInterceptor ipRateInterceptor(IpRateProperties ipRateProperties, StringRedisTemplate stringRedisTemplate) {
        return new IpRateInterceptor(ipRateProperties, stringRedisTemplate);
    }
}
